package com.qidian.blog.servlet;

import com.qidian.blog.factory.ServiceFactory;
import com.qidian.blog.pojo.BlogConfig;
import com.qidian.blog.service.BlogConfigService;
import com.qidian.blog.util.pojo.QDResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author 郭浩
 * @Date 2022/10/10 14:59
 */
@WebServlet("/config")
public class BlogConfigServlet extends BaseServlet{
    private BlogConfigService service = ServiceFactory.getService(BlogConfigService.class);
    public void query(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        BlogConfig config = service.query();
        respJson(QDResult.ok(config),resp);
    }
    public void update(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        String blogName = req.getParameter("blogName");
        String nickName = req.getParameter("nickName");
        String headUrl = req.getParameter("headUrl");
        String personalDesc = req.getParameter("personalDesc");
        String linkInfo = req.getParameter("linkInfo");
        String regist = req.getParameter("regist");
        String message = req.getParameter("message");
        String remark = req.getParameter("remark");
        String imagePath = req.getParameter("imagePath");
        String imageServerUrl = req.getParameter("imageServerUrl");
        BlogConfig blogConfig = new BlogConfig();
        blogConfig.setBlogName(blogName);
        blogConfig.setNickname(nickName);
        blogConfig.setHeadUrl(headUrl);
        blogConfig.setPersonalDesc(personalDesc);
        blogConfig.setLinkInfo(linkInfo);
        blogConfig.setRegist(new Integer(regist));
        blogConfig.setMessage(new Integer(message));
        blogConfig.setRemark(new Integer(remark));
        blogConfig.setImagePath(imagePath);
        blogConfig.setImageServerUrl(imageServerUrl);
        QDResult update = service.update(blogConfig);
        respJson(update,resp);
    }
}
